home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11051 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.sinet.slb.com!usenet
  2. From: "Vinh D. Nguyen" <vnguyen@sugar-land.anadrill.slb.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Calling DLL-Functions?
  5. Date: Tue, 12 Mar 1996 08:08:58 -0600
  6. Organization: Schlumberger Anadrill
  7. Message-ID: <3145857A.5BD2@sugar-land.anadrill.slb.com>
  8. References: <4hhsr6$vm5@taco.cc.ncsu.edu> <4hktpc$1h2@vega.info.isbiel.ch>
  9. NNTP-Posting-Host: 163.185.118.40
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Juestrich Marc wrote:
  16. > I'm just a beginner in programming C/C++, so it's maybe easy to anser this
  17. > basic question:
  18. > How can I call a Function in a DLL. I've got the description of this DLL and I
  19. > also was reading something about LoadLibrary or GetProcAdd etc.
  20. > Is this the right way to go? Could you please give me an example?
  21. > What are the advanteges of Link-or Runtime linking?
  22. > Please mail me     Marc
  23. > (excuse my bad english)
  24.  
  25. To call a function in a DLL, you can use one of two approaches:
  26.  
  27. 1. Use LoadLibrary to load the DLL at runtime and then use GetProcAddress
  28.    to retrieve the address of the fucntion you want to call. This approach is
  29.    more dynamic since you can check for the existence of the DLL and the function
  30.    before invoking it. You can also call the same function in alternative DLLs
  31.    depending on their existence or some other critera.
  32.  
  33. 2. When you build a DLL, you can also generate something called the import libary
  34.    ( with the .lib) extension. This import library acts like a static library in
  35.    the sense that you link it into your application at compile (actually link) time.
  36.    The import library simply contains a table of offsets for the functions in the
  37.    DLL so that you can call the function directly as if the function is contained in
  38.    a static library. The drawback of this approach is the existence of the library is
  39.    checked when the application is launched. If the DLL does not exist, your application
  40.    will shutdown. In other words, it's an all-or-nothing deal.
  41.  
  42. Hope this helps.
  43.  
  44. -- 
  45. --------------------------------------------------------------------------
  46. * Vinh Nguyen                                            vnguyen@slb.com *
  47. * Drilling Information Products - Senior Engineer                        *
  48. * Anadrill Schlumberger                             *
  49. * 200 Gillingham Ln.                             (713) 275-7524 (Office) *
  50. * Sugarland, TX 77478                            (713) 275-8098 (FAX)    *
  51. --------------------------------------------------------------------------
  52.